/*************************************************************************
 * AUTHOR		 : Chris Hayes
 * STUDENT ID	 : 656960
 * ASSIGNMENT #5 : Multi-Dimensional Array - Tic Tac Toe
 * CLASS		 : CS1B
 * SECTION		 : MW12:30
 * DUE DATE		 : June 15, 2011
 *************************************************************************/

#include "tictacheader.h"

/**************************************************************************
* FUNCTION SwitchPlayers
*__________________________________________________________________________
* This function askes the players if they would like to switch X and O.
*__________________________________________________________________________
* PRE-CONDITIONS
*  player1 : The name of player1 should be previously defined  - Reference
*  player2 : The name of player2 should be previously defined  - Reference
*  score1  : The score of player1 should be previously defined - Reference
*  score2  : The score of player2 should be previously defined - Reference
*
* POST-CONDITIONS
*   If the answer is yes, then player1 becomes player2, score1 becomes
*   score2 and vice-versa.
**************************************************************************/

void SwitchPlayers(string& player1, int& score1, string& player2, int& score2)
{
	string tempName;	//Used to store the name while switching
						//								- CALC
	int tempScore;		//Used to store the score while switching
						//								- CALC
	char answer;		//the answer of the question 	- IN & CALC
	bool invalid;		//used during error checking	- CALC

	cout << "Would you like to switch X and O (y or n)? ";
	do
	{
		invalid = false;

		cin.get(answer);
		cin.ignore(100, '\n');

		answer = toupper(answer);

		if(answer != 'Y' && answer != 'N')
		{
			invalid = true;
			cout << "Please enter y for YES or n for NO\n";
			cout << "Would you like to switch X and O? ";
		}
	}while(invalid);

	if(answer == 'Y')
	{
		//Switch players - player 1 is always 'X'
		tempName = player1;
		player1 = player2;
		player2 = tempName;

		//switch scores so they stay associated with their players
		tempScore = score1;
		score1 = score2;
		score2 = tempScore;
	}
}
